package se.webbzon.boltzmann.effect;

import se.webbzon.boltzmann.resource.Resources;
import se.webbzon.oschi01.worldarea.WorldArea;
import se.webbzon.oschi01.worldobject.WorldStaticObject;

public class HealthLossEffect extends TextureEffect {
	
	// The start y-position
	private final double yStart;
	
	// The shadow of this effect
	private final Shadow2DEffect shadow;
	
	/*============================================================
	Constructors
	============================================================*/

	public HealthLossEffect(WorldStaticObject parent) {
		super(parent, Resources.getTextureSet("effect_health_drop"),45 + (int) (45 * Math.random()));
		setPosition(parent.getX(),parent.getY()-parent.getHeight()/2,parent.getZ());
		yStart = getY();
		shadow = new Shadow2DEffect(this,Resources.getTextureSet("effect_shadow_circle"));
		
		final double direction = 2*Math.PI*Math.random();
		final double speed = 1.5+Math.random();
		setVelocity(speed * Math.cos(direction),3*speed,speed * Math.sin(direction));
		setAcceleration(0,-0.4,0);
		setSize(16,16,16);
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onEffectBegin(WorldArea world) {
		shadow.launch(world);
		shadow.setPosition(getX(), yStart, getZ());
	}

	@Override public void onEffectStep(WorldArea world) {
		if (getY() < yStart) {
			setPosition(getX(),yStart,getZ());
			setVelocity(getXVelocity(),-0.80*getYVelocity(),getZVelocity());
		}
	}

	@Override public void onEffectEnd(WorldArea world) {
		shadow.terminate(world);
	}

}
